package com.newland.server.config;

import com.newland.server.utils.AjaxResponse;
import com.newland.server.utils.CustomException;
import com.newland.server.utils.CustomExceptionType;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler({UnauthorizedException.class, AuthorizationException.class})//全局捕获扔出来的权限异常,以json的格式返回给前端,剩下的就交给前端处理
    @ResponseBody
    public AjaxResponse customerException(Exception e) {
        return AjaxResponse.error(new CustomException(CustomExceptionType.USER_INPUT_ERROR,e.getMessage()));
    }
}
